package com.weixing.mall.provider.controller.cms;

import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.annotation.NoRepeatSubmit;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.provider.model.dto.cms.BannerDto;
import com.weixing.mall.provider.model.query.BannerQuery;
import com.weixing.mall.provider.service.IBannerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName BannerController
 * @Description TODO <br/>
 * @Author gjq
 * @Modified By:
 * @Date 2019/7/26
 * @Version 1.0
 **/
@RestController
@RequestMapping("banner")
@Api(value = "轮播图APi", tags = "轮播图")
public class BannerController extends BaseController {

    @Autowired
    private IBannerService bannerService;

    @ApiOperation(value = "加载轮播图列表")
    @GetMapping("")

    public Result list(BannerQuery bannerQuery) {
        return ResultUtil.success(bannerService.selectOfPage(initMpPage(), bannerQuery));
    }

    @ApiOperation(value = "通过id查询轮播图详情")
    @GetMapping("getBannerById/{id}")
    public Result getBannerById(@PathVariable long id) {
        return ResultUtil.success(bannerService.getBannerById(id));
    }

    @ApiOperation(value = "保存轮播图信息")
    @PostMapping("save")
    @NoRepeatSubmit
    public Result save(@Validated BannerDto bannerDto) {
        bannerService.save(bannerDto);
        return ResultUtil.success();
    }

    @ApiOperation(value = "删除轮播图")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "轮播图id", paramType = "path", dataType = "long")
    })
    @PostMapping("del/{id}")
    public Result del(@PathVariable long id) {
        return bannerService.removeById(id)? ResultUtil.success() : ResultUtil.error();
    }

    @ApiOperation(value = "批量删除品牌")
    @PostMapping("delAll/{ids}")
    public Result delAll(@PathVariable int[] ids){
        bannerService.deleteAll(ids);
        return ResultUtil.success();
    }


}
